<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h2>Cadastrar Curso</h2>

            <p:panel styleClass="container_24 clearfix " style="background: none; border: none;"> 
                <h:form id="form" acceptcharset="utf-8">
                    <p:growl id="msg" life="3000" autoUpdate="true" showDetail="false"/>

                    <p class="subtitle"> Dados Gerais</p>

                    <p:outputLabel value="Código:" styleClass="grid_3" for="codigoInputText">
<!--                        <span class="ui-outputlabel-rfi required">*</span>-->
                    </p:outputLabel>
                    <p:inputText id="codigoInputText" styleClass="grid_7"
                                 required="true" value="#{managerCriarCurso.curso.codigo}"/>
                    <div class="clear"/>

                    <p:outputLabel value="Nome:" styleClass="grid_3" for="nomeInputText">
<!--                        <span class="ui-outputlabel-rfi required">*</span>-->
                    </p:outputLabel>
                    <p:inputText id="nomeInputText" styleClass="grid_20"
                                 required="true" value="#{managerCriarCurso.curso.nome}" />
                    
<!--                    <div class="buttonAction">
                        <p:commandButton value="Adicionar" icon="ui-icon-plus" 
                                         actionListener="#{managerCriarCurso.adicionar()}" 
                                         update="@form" styleClass="ui-priority-primary"/>
                    </div>
                    
                    <p class="subtitle">Resultado</p>

                    <p:dataTable id="cursoDataTable" value="#{managerCriarCurso.cursos}" var="item"
                                 styleClass="grid_24" emptyMessage="Nenhum registro">

                        <f:facet name="header">
                            Cursos
                        </f:facet>

                        <p:column headerText="Ação" width="50">
                            <p:commandButton title="Editar"
                                             actionListener="#{managerCriarCurso.editar()}"
                                             icon="ui-icon-pencil" update="@form" >
                                <f:setPropertyActionListener target="#{managerCriarCurso.curso}" value="#{item}" />
                            </p:commandButton>
                            <p:commandButton title="Excluir" oncomplete="dlg.show()"
                                             icon="ui-icon-trash" update="@form" >
                                <f:setPropertyActionListener target="#{managerCriarCurso.cursoDelete}" value="#{item}" />
                            </p:commandButton>
                        </p:column>

                        <p:column headerText="Código" width="180">  
                            #{item.codigo}
                        </p:column>

                        <p:column headerText="Nome">  
                            #{item.nome}
                        </p:column> 

                    </p:dataTable>-->

                    <div class="clear"/>
                    <div class="buttonAction">
                        <p:commandButton value="Salvar" icon="ui-icon-disk" 
                                         actionListener="#{managerCriarCurso.salvar()}" 
                                         update="@form" styleClass="ui-priority-primary"/>
                        <p:button value="Cancelar" icon="ui-icon-circle-close"
                                  href="indexcurso.xhtml"/>

                    </div>
                    
                    <p:dialog id="modalDialog" header="Confirmação de remoção" widgetVar="dlg" modal="true" 
                              height="80" closable="true" resizable="false" >
                        <h:outputText value="Tem certeza que deseja remover este curso?" />
                        <div class="buttonAction">
                            <p:commandButton value="Sim" disabled="#{managerCriarCurso.cursos.isEmpty()}"
                                             actionListener="#{managerCriarCurso.deletar()}"
                                             update="@form"
                                             icon="ui-icon-check"/>
                            <p:commandButton value="Não" icon="ui-icon-close"
                                             oncomplete="dlg.hide()" />

                        </div>
                    </p:dialog>
                </h:form>
            </p:panel> 
            
            <script language="JavaScript" type="text/javascript">
                function required(rqd){
                    if(rqd){
                        $('#form .ui-outputlabel').each(function() {
                            var id = $(this).attr('for').replace(':', '\\:');
                            /* <![CDATA[ */
                            if ($(this).children('span').hasClass('required') && ($('#' + id).val() == '')) {
                                $(this).addClass('ui-state-error');
                                $('#' + id).addClass('ui-state-error');
                            }
                            /* ]]> */
                        });
                    }else{
                        $('#protocoloForm\\:processoCamposPanel').children().removeClass('ui-state-error');
                    }
                }
            </script>
        </ui:define>
    </ui:composition>
</html>